//
//  StationTableViewController.m
//  Runone
//
//  Created by runone01 on 16/9/7.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "StationTableViewController.h"
#import "AppDelegate.h"
#import "StationModel.h"
#import "RequestHelper.h"
#import "StationModel.h"
#import "Define.h"
#import "ParModel.h"
#import "MJExtension.h"
#import "HighWayRoadRecord.h"
@interface StationTableViewController ()
@property(nonatomic,strong)NSArray *dataSource;
@property(nonatomic,copy)NSString *uid;
@property(nonatomic,strong)ParModel *model;
@property(nonatomic,strong)NSArray *allStationName;
@property(nonatomic,strong)NSMutableArray *tempArray;
@property(nonatomic,strong)HighWayRoadRecord *tempModel;
@end

@implementation StationTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _model=[[ParModel alloc] init];
    _model.key=@"TollStationUID";
//    NSMutableArray *mutable = [[NSMutableArray alloc] init];
//    AppDelegate *myDelegate = (AppDelegate*) [UIApplication sharedApplication].delegate;
//     _tempModel             = myDelegate.HighWayRoadArray[0];
//    
//    HighWayRoadRecord *model=myDelegate.HighWayRoadArray[1];
//    mutable=[NSMutableArray arrayWithArray:model.TollStationList];
//    
//    StationModel *stationModel=mutable[1];
//    
//    _tempArray =[NSMutableArray arrayWithArray:_tempModel.TollStationList];
//    [_tempArray removeObjectAtIndex:0];
//    [_tempArray removeObjectAtIndex:_tempArray.count-1];
//    [_tempArray addObject:stationModel];
    self.preferredContentSize=CGSizeMake(145, 175);
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"LineCell"];

    _tempArray = [[NSMutableArray alloc] init];
    AppDelegate *myDelegate = (AppDelegate*) [UIApplication sharedApplication].delegate;
    [_tempArray  addObjectsFromArray:myDelegate.AllTollStationArray];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _tempArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellID=@"LineCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID forIndexPath:indexPath];
    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellID];
    }
    StationModel *model=_tempArray[indexPath.row];
//    cell.textLabel.text=_dataSource[indexPath.row];
    cell.textLabel.text=[NSString stringWithFormat:@"%@",model.TollStationName];
    // Configure the cell...
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.LineBlock!=nil) {
        self.LineBlock(_tempArray[indexPath.row]);
    }
    StationModel *model=_tempArray[indexPath.row];
    
    _uid = model.TollStationUID;
    _model.value=_uid;
   
    [self request];
    [self dismissViewControllerAnimated:YES completion:nil];
}
//
-(NSString *)jsonstrong {
    NSMutableDictionary *dic=_model.mj_keyValues;
    NSString *str=[dic mj_JSONString];
    NSString *str1=@"[";
    NSString *temp=[str1 stringByAppendingString:str];
    NSString *str2=@"]";
    NSString *JsonString=[temp stringByAppendingString:str2];
    return JsonString;
}

-(void)request
{
    RequestHelper *requestHelper=[[RequestHelper alloc] init];
    RequestGinsengModel *getCurrentEventModel=[[RequestGinsengModel alloc] init];
    getCurrentEventModel.URL=GetCurrentDutyPersonalName;
    getCurrentEventModel.DataValue = [self jsonstrong];
    getCurrentEventModel.UpdatedTime=@"2012-01-12 12:00:00";
    getCurrentEventModel.SystemCode=@"GuangleHighway";
    getCurrentEventModel.MethodName=@"GetCurrentDutyPersonalName";
    
    requestHelper.block=^(RequestOutginseng *requestOutginseng,id dataValueModel){
        NSString *name=[[requestOutginseng valueForKey:@"DataValue"] mj_JSONString];
        //NSString *name = [dic mj_JSONString];
        if (self.NameBlock!=nil) {
            self.NameBlock(name);
        }
    };
    [requestHelper RequestGinsengModel:getCurrentEventModel andPushController:self];
}




@end
